package com.link.auth.base.user.authority;

import com.link.auth.core.interceptors.MyInterceptor;
import com.link.auth.util.PasswordUtil;
import org.springframework.security.crypto.password.PasswordEncoder;

public class UserPasswordEncoder implements PasswordEncoder {

    private static final String CORPWX_MP_ENTRANCE = "corpwxmp";

    @Override
    public String encode(CharSequence charSequence) {
        return null;
    }

    @Override
    public boolean matches(CharSequence charSequence, String s) {

//        String result = PasswordUtil.generatePwd(charSequence.toString());
//        System.out.println("result:" + result);
//        return result.equals(s);
        //当thridLoginFlag为Y，表示当前是app第三方登录
        String thridLoginFlag = MyInterceptor.getThirdLoginFlag().get();
        String scope = MyInterceptor.getScopeThread().get();
        if (CORPWX_MP_ENTRANCE.equals(scope)) {
            return charSequence != null && charSequence.equals(s);
        }
        return "Y".equals(thridLoginFlag) || PasswordUtil.isEquals(charSequence, s);
    }
}
